﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ReportingManagement.Components
{
    /// <summary>
    /// Interaction logic for OfflineDataCutOffPoint.xaml
    /// </summary>
    public partial class OfflineDataCutOffPoint : Window
    {
        public OfflineDataCutOffPoint()
        {
            InitializeComponent();

            DateTime sixMonthsAge = DateTime.Now.AddMonths(-6);
            datePicker.SelectedDate = sixMonthsAge;
        }

        private DateTime cutOffPoint;
        public DateTime CutOffPoint
        {
            get
            {
                return cutOffPoint;
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            // This is the default cut-off point
            DateTime twoYearsAgo = DateTime.Now.AddYears(-2);
            cutOffPoint = twoYearsAgo;

            if (rdoLastYear.IsChecked.HasValue && rdoLastYear.IsChecked.Value)
            {
                DateTime lastYear = DateTime.Now.AddYears(-1);
                cutOffPoint = lastYear;
            }

            if (rdoLastSixMonths.IsChecked.HasValue && rdoLastSixMonths.IsChecked.Value)
            {
                DateTime lastSixMonths = DateTime.Now.AddMonths(-6);
                cutOffPoint = lastSixMonths;
            }

            if (rdoSpecifyDate.IsChecked.HasValue && rdoSpecifyDate.IsChecked.Value)
            {
                cutOffPoint = datePicker.SelectedDate.Value;
            }

            DialogResult = true;
            this.Close();
        }
    }
}
